1893. 检查是否区域内所有整数都被覆盖
为保证权益,题目请参考 1893. 检查是否区域内所有整数都被覆盖(From LeetCode).
解决方案1
Python
python
# 1893. 检查是否区域内所有整数都被覆盖
# https://leetcode-cn.com/problems/check-if-all-the-integers-in-a-range-are-covered/
from typing import List
class Solution:
def isCovered(self, ranges: List[List[int]], left: int, right: int) -> bool:
diff = [0] * 52
for l, r in ranges:
diff[l] += 1
diff[r + 1] -= 1
prefix = 0
for i in range(1, 51):
prefix += diff[i]
if i >= left and i <= right and prefix == 0:
return False
return True
#
# 这个题目,开拓的新的思路,查分数组加前缀和的方式
#
if __name__ == "__main__":
solution = Solution()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27